#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#define FILENUM(number) "log.txt"#number

int main()
{
    int fd0 = open(FILENUM(0),O_WRONLY | O_CREAT,0664);
    int fd1 = open(FILENUM(1),O_WRONLY | O_CREAT,0664);
    int fd2 = open(FILENUM(2),O_WRONLY | O_CREAT,0664);
    int fd3 = open(FILENUM(3),O_WRONLY | O_CREAT,0664);

    if(fd0==-1)
        perror("open");
    const char* msg = "my name is wml!\n";
    int cnt = 5;
    char buffer[128];
    while(cnt)
    {
        sprintf(buffer,"%s:%d\n","hello",cnt--);
        write(fd1,buffer,strlen(buffer));
    }
   

    printf("fd0:%d\n",fd0);
    printf("fd1:%d\n",fd1);
    printf("fd2:%d\n",fd2);
    printf("fd3:%d\n",fd3);
    
    int fd = open(FILENUM(0),O_RDONLY);
    char buffer1[128];
    ssize_t num = read(fd,buffer1,sizeof(buffer1)-1);
   // printf("%d\n",num);
    if(num>0) buffer1[num] = 0;
    printf("%s",buffer1);

    close(fd0);
    close(fd1);
    close(fd2);
    close(fd3);
    return 0;
    //printf("stdin-->fd:%d\n",stdin->_fileno);    
    //printf("stdout-->fd:%d\n",stdout->_fileno);    
    //printf("stderr-->fd:%d\n",stderr->_fileno);    
    //return 0;
}
